var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, function(err, db) {
    if (err) throw err;
    // console.log("数据库已创建!");
    var dbase = db.db("runoob");   // 创建的数据库名【runoob】

    // 插入一条数据
    // var myobj = { name: "菜鸟教程1", url: "www.runoob" };  // 要插入的数据
    // dbase.collection('site').insertOne(myobj, function(err, res){
    //     if(err) throw err;
    //     console.log('文档插入成功');
    //     db.close()
    // })

    //插入多条数据
    var myobj2 = [
        { name: '小一', age: '14', type: 'cn'},
        { name: '小二', age: '18', type: 'en'},
        { name: '小三', age: '17', type: 'en'},
        { name: '小四', age: '24', type: 'en'},
        { name: '小五', age: '20', type: 'en'},
    ];
    dbase.collection("site").insertMany(myobj2, (err, res)=>{
        if(err) throw err
        console.log("插入的文档数量为："+ res.insertedCount);
        db.close();
    })
});